package wli.web.servlet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet(urlPatterns = { "/index" }, initParams = {
		@WebInitParam(name = "jboss_home", value = "http://localhost:8000/JBoss"),
		@WebInitParam(name = "base_dir", value = "C:\\Apache"),
		@WebInitParam(name = "file_host", value = "http://localhost:8000") })
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	String base_dir;
	String file_host;
	String jboss_home;

	public void init(ServletConfig config) throws ServletException {
		jboss_home = config.getInitParameter("jboss_home");
		base_dir = config.getInitParameter("base_dir");
		file_host = config.getInitParameter("file_host");
		System.out.println("\n>>>>>>>>>>>>>>>" + base_dir);
		System.out.println("\n>>>>>>>>>>>>>>" + file_host);
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out;
		try {
			out = response.getWriter();

			File f = new File(".");

			out.println("<html>");
			out.println("<head>");
			out.println("<title>William Li's Daily Logs</title>");
			out.println("</head>");
			out.println("<bod>");
			out.println("<h3>");
			out.println("<br><a href=" + jboss_home+" target=_black>Jboss document</a>");
			out.println("<br>base_dir=======" + base_dir);
			out.println("<br>file_home=======" + file_host);
			out.println("</h3>");
			out.println("</body>");
			out.println("</html>");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
